#ifndef CHDF5DATASETOBJECT_H
#define CHDF5DATASETOBJECT_H
#ifdef OLD_HEADER_FILENAME
#include <iostream.h>
#else
#include <iostream>
#endif
#include <string>

#ifndef H5_NO_NAMESPACE
#ifndef H5_NO_STD
using std::cout;
using std::endl;
#endif  // H5_NO_STD
#endif

#include "H5Cpp.h"

#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif

#include <vector>
#include <sys/stat.h> 
using namespace std;

class CHDF5DataSetObject
{

public:
	/*!
	* \brief This enum type 
	* create: write CHDF5 object to a new dataset or group. 
	* append: append CHDF5 object to an existing dataset or group.
	*/
	//typedef enum accessType{create=0,append};

public:
	CHDF5DataSetObject(int Rank,const hsize_t *dims,DataType& dataType);

	virtual ~CHDF5DataSetObject();

public:
	virtual int read(H5File* h5_file,const H5std_string& location,void* dataOut);
	virtual int write(H5File* h5_file,const H5std_string& location, void* data);
	virtual int append(H5File* h5_file,const H5std_string& location, void* data);

	int getSize(H5File* h5_file,const H5std_string& location);

	int createAttribute(H5File* h5_file,const H5std_string& dataSetName,H5std_string& attrName,DataType& attrType,const void* data);

	int readAttribute(H5File* h5_file,const H5std_string& dataSetName,H5std_string& attrName,DataType& attrType,void* data);

	int modifyAttribute(H5File* h5_file,const H5std_string& dataSetName,H5std_string& attrName,DataType& attrType,const void* data);

	H5std_string GetErrMsg() const;
private:
	bool isFileExist(const H5std_string& filename);

	bool isDataSetExist(H5File* h5_file,const H5std_string& location);
	void createDataSet(H5File* h5_file,const H5std_string& location);

	bool isGroupExist(H5File* h5_file,const H5std_string& location);
	void createGroups(H5File* h5_file,vector<H5std_string>& paths);
	
protected:
	H5std_string errMsg;
	const int rank;
	const hsize_t* dimensions;
	DataType dType;
	const void* buf;
	int size;
};

#endif